<template>
  <div>
    <el-card>
      <div class="header_button">
        <el-button type="primary" :icon="Plus" plain @click="onAdd"
          >添加</el-button
        >
        <el-button
          type="danger"
          plain
          :icon="Delete"
          @click="onAllDelete"
          :disabled="allDelete.length > 0 ? false : true"
          >删除</el-button
        >
      </div>
      <el-table
        :data="tableData"
        :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column label="ID" align="center" prop="id" />
        <el-table-column label="域名" align="center" prop="domain_name" />
        <el-table-column label="站点名称" align="center" prop="site_name" />
        <el-table-column label="路径" align="center" prop="path" />
        <el-table-column label="动态页后缀" align="center" prop="dynamic" />
        <el-table-column label="静态页后缀" align="center" prop="static" />
        <el-table-column
          label="前台本地化"
          align="center"
          prop="localization"
        />
        <el-table-column label="操作" align="center">
          <template #default="{ row }">
            <el-button link type="primary" @click="onUpdate(row)"
              >修改</el-button
            >
            <el-button link type="primary" @click="onDelete(row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @change="handelPagination"
      />

      <ComponentDialog
        ref="dialogRef"
        :dialogRowList="dialogRowList"
        :title="title"
      />
    </el-card>
  </div>
</template>

<script  setup>
import { Delete, Plus } from '@element-plus/icons-vue'
import { ref } from 'vue'
import ComponentDialog from '@/views/disposition/siteManagement/component/dialog.vue'
const total = ref(50)
const queryParams = ref({
  pageNum: 1,
  pageSize: 10
})
const dialogRowList = ref({})
const tableData = ref([
  {
    id: 1,
    domain_name: 'localhost',
    site_name: '中国保信',
    path: 'model',
    dynamic: '.html',
    static: 'html',
    localization: 'zh_CN'
  },
  {
    id: 2,
    domain_name: 'localhost',
    site_name: '中国保信',
    path: 'model',
    dynamic: '.html',
    static: 'html',
    localization: 'zh_CN'
  },
  {
    id: 3,
    domain_name: 'localhost',
    site_name: '中国保信',
    path: 'model',
    dynamic: '.html',
    static: 'html',
    localization: 'zh_CN'
  }
])
const allDelete = ref([])
const title = ref('')
const getList = () => {
  // 后端接口
}
// 修改
const dialogRef = ref(null)
const onUpdate = (row) => {
  title.value = '修改'
  dialogRef.value.dialogVisible = true
  dialogRowList.value = row
}
// 添加
const onAdd = () => {
  title.value = '添加'
  dialogRef.value.dialogVisible = true
  dialogRowList.value = {}
}
// 单个删除
const onDelete = (row) => {
  // 删除接口
  console.log(row)
}
// 多项删除
const onAllDelete = () => {
  // 多项删除接口
  console.log(allDelete.value)
}
// 选择表格多条数据
const handleSelectionChange = (value) => {
  allDelete.value = []
  value.map((item) => {
    allDelete.value.push(item.id)
  })
}
// 分页
const handelPagination = (currentPage, pageSize) => {
  queryParams.value.pageNum = currentPage
  queryParams.value.pageSize = pageSize
}
getList()
</script>

<style lang="scss" scoped>
.header_button {
  margin-left: auto;
  margin: 20px;
  text-align: right;
}
.button_row {
  text-align: center;
  margin-top: 30px;
}
</style>
